package com.example.onlinemarket.bean.mobile;

import com.example.onlinemarket.bean.Good;

import java.util.ArrayList;
import java.util.List;

import static com.example.onlinemarket.util.FileUtil.byte2image;
import static com.example.onlinemarket.util.FileUtil.prefixPath;

public class MobileGood {
    private Integer goodId;//鲜花ID
    private String goodName;//鲜花名
    private Integer quantity;//鲜花库存
    private Integer sellNum;//鲜花销量
    private Double sellPrice;//鲜花售价
    private Double purchasePrice;//鲜花进价
    private Integer userId;//商家ID
    private String description;//鲜花描述
    private String species;//鲜花种类
    private boolean status;//鲜花状态(上架/下架)
    private String imgPath;//图片路径

    public MobileGood(Good good){
        this.goodId = good.getGoodId();
        this.goodName = good.getGoodName();
        this.quantity = good.getQuantity();
        this.sellNum = good.getSellNum();
        this.sellPrice = good.getSellPrice();
        this.userId = good.getUserId();
        this.description = good.getDescription();
        this.species = good.getSpecies();
        this.status = good.isStatus();
        String fileName  = good.getGoodId()+".jpg";
        String path = prefixPath+"good\\"+fileName;
        byte2image(good.getPhoto(), path);
        this.imgPath="/good/"+fileName;
    }

    //返回顾客查询的MobileGood数组，信息不含进价
    public static List<MobileGood> getMobileGoodsByCustomer(List<Good> goods){
        List<MobileGood> mobileGoodList = new ArrayList<>();
        for (Good good: goods){
            mobileGoodList.add(getMobileGoodByCustomer(good));
        }
        return mobileGoodList;
    }

    //返回顾客查询的MobileGood，信息不含进价
    public static MobileGood getMobileGoodByCustomer(Good good){
        return new MobileGood(good);
    }

    //返回店主查询的MobileGood数组，信息不含进价
    public static List<MobileGood> getMobileGoodsByShopOwner(List<Good> goods){
        List<MobileGood> mobileGoodList = new ArrayList<>();
        for (Good good: goods){
            mobileGoodList.add(getMobileGoodByShopOwner(good));
        }
        return mobileGoodList;
    }

    //返回店主查询的MobileGood，信息包含进价
    public static MobileGood getMobileGoodByShopOwner(Good good){
        MobileGood mobileGood = new MobileGood(good);
        mobileGood.setPurchasePrice(good.getPurchasePrice());
        return mobileGood;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }

    public Integer getGoodId() {
        return goodId;
    }

    public void setGoodId(Integer goodId) {
        this.goodId = goodId;
    }

    public String getGoodName() {
        return goodName;
    }

    public void setGoodName(String goodName) {
        this.goodName = goodName;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Integer getSellNum() {
        return sellNum;
    }

    public void setSellNum(Integer sellNum) {
        this.sellNum = sellNum;
    }

    public Double getSellPrice() {
        return sellPrice;
    }

    public void setSellPrice(Double sellPrice) {
        this.sellPrice = sellPrice;
    }

    public Double getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(Double purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSpecies() {
        return species;
    }

    public void setSpecies(String species) {
        this.species = species;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }
}
